
import org.junit.jupiter.api.Test;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.TextStyle;
import java.util.Arrays;
import java.util.Locale;

public class DayOfWeekDemo {
    /**
     * DayOfWeek枚举类的所有枚举值。
     */
    @Test
    public void test01(){
        System.out.println(DayOfWeek.MONDAY); // 输出 MONDAY
        System.out.println(DayOfWeek.TUESDAY); // 输出 TUESDAY
        System.out.println(DayOfWeek.WEDNESDAY); // 输出 WEDNESDAY
        System.out.println(DayOfWeek.THURSDAY); // 输出 THURSDAY
        System.out.println(DayOfWeek.FRIDAY); // 输出 FRIDAY
        System.out.println(DayOfWeek.SATURDAY); // 输出 SATURDAY
        System.out.println(DayOfWeek.SUNDAY); // 输出 SUNDAY
    }
}

class DayOfWeekDemo01 {

    /**
     * from(TemporalAccessor temporal)
     * 作用：从其他含有星期数据的时间类获取dayOfWeek对象。
     */
    @Test
    public void test01(){
        LocalDate date01 = LocalDate.parse("2023-04-02"); // 2023-04-02 星期天
        DayOfWeek dayOfWeek = DayOfWeek.from(date01);
        System.out.println(dayOfWeek); // 输出 SUNDAY
    }

    /**
     * of(int dayOfWeek)
     * 作用：根据给定的数字（1~7）获取枚举值。
     */
    @Test
    public void test02(){
        System.out.println(DayOfWeek.of(1)); // 输出 MONDAY
        System.out.println(DayOfWeek.of(2)); // 输出 TUESDAY
        System.out.println(DayOfWeek.of(3)); // 输出 WEDNESDAY
    }

    /**
     * valueOf(String name)
     * 作用：根据给定的字符串获取枚举值。
     */
    @Test
    public void test03(){
        DayOfWeek monday = DayOfWeek.valueOf("MONDAY");
        System.out.println(monday); // 输出 MONDAY
    }

    /**
     * values()
     * 作用：获取所有枚举值（有序）
     */
    @Test
    public void test04(){
        DayOfWeek[] weeks = DayOfWeek.values();
        System.out.println(Arrays.toString(weeks)); // 输出 [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
    }
}

class DayOfWeekDemo02 {
    /**
     * adjustInto(Temporal temporal)
     * 作用：temporal是其它时间类对象，该方法的作用是将其他时间类对象的星期数据修改成dayOfWeek。
     */
    @Test
    public void test01(){
        LocalDate date01 = LocalDate.parse("2023-05-10"); // 2023-05-10（星期三）
        DayOfWeek tuesday = DayOfWeek.TUESDAY;
        DayOfWeek thursday = DayOfWeek.THURSDAY;
        LocalDate date02 = (LocalDate) tuesday.adjustInto(date01);
        LocalDate date03 = (LocalDate) thursday.adjustInto(date01);
        System.out.println(date01); // 输出 2023-05-10（星期三）
        System.out.println(date02); // 输出 2023-05-09（星期二）
        System.out.println(date03); // 输出 2023-05-11（星期四）
    }

    /**
     * getDisplayName(TextStyle style, Locale locale)
     * 作用：获取dayOfWeek对象文本表示形式。
     * 参数：
     *  style：文本表示方式。如：FULL显示完整的名称，SHORT显示简写的名称，NARROW显示短的名称。
     *  locale：本地化名称。如：Locale.CHINA显示中文名称，Locale.US显示英文名称。
     */
    @Test
    public void test02(){
        DayOfWeek tuesday = DayOfWeek.TUESDAY;
        System.out.println(tuesday.getDisplayName(TextStyle.FULL, Locale.US)); // 输出 Tuesday
        System.out.println(tuesday.getDisplayName(TextStyle.SHORT, Locale.US)); // 输出 Tue
        System.out.println(tuesday.getDisplayName(TextStyle.NARROW, Locale.US)); // 输出 T
        System.out.println(tuesday.getDisplayName(TextStyle.FULL, Locale.CHINA)); // 输出 星期二
    }

    /**
     * getValue()
     * 作用：获取星期对应的整数值（1~7）。
     */
    @Test
    public void test03(){
        DayOfWeek tuesday = DayOfWeek.TUESDAY;
        System.out.println(tuesday.getValue()); // 输出 2
    }

    /**
     * plus(long months)
     * minus(long months)
     * 作用：加上或减去固定值获取另一个的dayOfWeek对象。
     */
    @Test
    public void test04(){
        DayOfWeek tuesday = DayOfWeek.TUESDAY;
        System.out.println(tuesday.plus(1)); // 输出 WEDNESDAY
        System.out.println(tuesday.minus(1)); // 输出 MONDAY
    }
}